﻿using Microsoft.EntityFrameworkCore;
using PHMEE.Entities.DaqInfo.TdDevices;
using PHMEE.EntityFrameworkCore;
using PHMEE.IRepositories.DaqInfo.TdDevices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;

namespace PHMEE.Repositories.DaqInfo.TdDevices
{
    public class TdDeviceAttributeRepository : EfCoreRepository<PHMEEDbContext, TdDeviceAttribute, Guid>, ITdDeviceAttributeRepository
    {
        public TdDeviceAttributeRepository(IDbContextProvider<PHMEEDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }
        /// <summary>
        /// 根据超级的id查出所有列
        /// </summary>
        /// <param name="superTableId"></param>
        /// <returns></returns>

        public async Task<List<TdDeviceAttribute>> GetAttributesBySuperTableIdAsync(Guid superTableId)
        {
            var dbContext = await GetDbContextAsync();
            return await dbContext.TdDeviceAttributes
                .Where(a => a.TdDeviceTypeId == superTableId)
                .ToListAsync();
        }
        /// <summary>
        /// 批量插入设备属性
        /// </summary>
        /// <param name="attributes">设备属性集合</param>
        /// <returns></returns>
        public async Task InsertManyAsync(IEnumerable<TdDeviceAttribute> attributes)
        {
            var dbContext = await GetDbContextAsync();
            await dbContext.AddRangeAsync(attributes);
            await dbContext.SaveChangesAsync();
        }
    }
}
